layui.define(['form'], function(exports){
  var $ = layui.$,form = layui.form;
  
  $('#fileThumbnailImg').change(function(){
  	  var file = this.files[0];
  	  // 创建FormData对象
  	  var formData = new FormData();
  	  formData.append('file', file);
  	  
  	  // 发送ajax请求
  	  var xhr = new XMLHttpRequest();
  	  xhr.open('POST', layui.setter.webRoot + '/common/device/img/upload.do', true);
  	  xhr.responseType = 'json'
  	  xhr.onreadystatechange = function() {
  	    if (xhr.readyState === 4 && xhr.status === 200) {
  	      // 上传成功的操作
  	      console.log('图片上传成功！');
  		  var res = xhr.response;
  		  if(res.code == 200){
  			$('input[name="thumbnailImg"]').val(res.body.path);
  			$('#thumbnailImg').attr("src",res.body.imgUrl);
  		  }
  	    } else if (xhr.readyState === 4 && xhr.status !== 200) {
  	      // 上传失败的操作
  	      console.log('图片上传失败！');
  	    }
  	  };
  	  xhr.send(formData);
  });
    
  $('#thumbnailImg').click(function(){
  	$('#fileThumbnailImg').click();
  });
  
  exports('device_type_edit2', {})
});